-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make errors support verbose formatting to print wrapped errors #1396
base: master
Are you sure you want to change the base?
Conversation
This makes it possible to print the entire hierarchy when using `%+v` - in particular, when running tests this will show causes and stack traces, not just the error message, which can help debugging tests.
{ | ||
name: "WorkflowExecutionError", | ||
err: NewWorkflowExecutionError("wid", "rid", "workflowType", newWorkflowPanicError("test message", "stack trace")), | ||
expected: "stack trace\ntest message\nworkflow execution error (type: workflowType, workflowID: wid, runID: rid): test message", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems odd to show inner error information before outer error information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically copied the behavior from github.com/pkg/errors - I did also think the same but for consistency it seemed like the best approach
@@ -820,6 +845,24 @@ func (e *WorkflowExecutionError) Unwrap() error { | |||
return e.cause | |||
} | |||
|
|||
func formatError(e error, s fmt.State, verb rune, verboseValue any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear the future proof-ness of this. If Go adds new print flags that'd work for errors, we'd silently not support them.
I wonder if it'd be better to change where you're formatting these errors to handle more advanced types instead of adding a formatting feature to a few of the errors here. I think that gives you the most flexibility instead of assuming exactly what people want when %+v
is put (you want stack trace, but another might want struct fields). We tend to put accessors on the errors for users to extract and display the way they prefer.
(having said that, I'm not completely against the change, I think it just makes too many assumptions of what users may want to see instead of encouraging them to extract the information themselves when they're displaying)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right it might be different what people want - I just copied the behavior from pkg/errors since that seems to be what a lot of people (including myself) are used to. I'd personally say that %+v
means max verbose, so dump anything that can be dumped, but again that might be a personal preference...
This makes it possible to print the entire hierarchy when using
%+v
- in particular, when running tests this will show causes and stack traces, not just the error message, which can help debugging tests.Closes #1395